import 'package:plugin_platform_interface/plugin_platform_interface.dart';

import 'models.dart';

/// 扩展平台接口，添加Pangle SDK相关方法
abstract class FlutterPanglePlatform extends PlatformInterface {
  FlutterPanglePlatform() : super(token: _token);

  static final Object _token = Object();
  static FlutterPanglePlatform? _instance;

  static FlutterPanglePlatform get instance {
    if (_instance == null) {
      throw StateError(
        'Platform interface not initialized. '
        'Make sure to initialize FlutterPanglePlatform.instance with a concrete implementation.',
      );
    }
    return _instance!;
  }
  
  // 允许内部访问_instance用于初始化检查
  static FlutterPanglePlatform? get internalInstance => _instance;
  
  static set instance(FlutterPanglePlatform instance) {
    PlatformInterface.verifyToken(instance, _token);
    _instance = instance;
  }

  /// 初始化SDK
  Future<bool> initializeSDK(PAGSSDKConfig config);

  /// 设置合规设置
  Future<void> setEligibleAudience(bool eligible);

  /// 设置内容语言（单个）
  Future<void> setContentLanguage(String language);

  /// 设置内容语言（多个）
  Future<void> setContentLanguages(List<String> languages);

  /// 获取默认短剧列表
  Future<PAGSFeedListResponse> requestFeedList({
    required int index,
    required int count,
  });

  /// 获取指定分类或短剧的列表
  Future<PAGSFeedListResponse> requestFeedListWithFilters({
    required int index,
    required int count,
    List<int>? categoryIds,
    List<int>? shortplayIds,
  });

  /// 获取热门短剧列表
  Future<PAGSFeedListResponse> requestPopularDrama({
    required int index,
    required int count,
  });

  /// 获取新剧列表
  Future<PAGSFeedListResponse> requestNewFeedList({
    required int index,
    required int count,
  });

  /// 获取指定标签的列表
  Future<PAGSFeedListResponse> requestDramaWithTag({
    required int tag,
    required int index,
    required int count,
  });

  /// 获取短剧分类列表
  Future<List<PAGSCategoryItem>> getCategoryList(String language);

  /// 搜索短剧
  Future<PAGSFeedListResponse> requestSearchDrama({
    required int index,
    required int count,
    required String keyword,
    required bool isFuzzy,
  });

  /// 检查当前地区是否支持播放
  Future<int> checkPlayStatus();

  /// 设置收藏状态
  Future<bool> setCollected({
    required bool collected,
    required int shortplayId,
  });

  /// 清除本地缓存
  Future<void> clearLocalCache();

  /// 获取设备当前语言
  /// 注意：由于Flutter method channel不支持同步调用，此方法在iOS端直接返回系统语言
  String getCurrentLanguage();

  /// 预热播放器引擎（可选）
  /// 在应用启动时调用，可以提前初始化播放器引擎，减少首次播放时的卡顿
  Future<void> warmUpPlayerEngine();
}
